package com.example.commonback.common.exception;

import com.example.commonback.common.result.Result;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 前端返回值异常处理类
 *
 * @author Lv
 * @date 2022/11/4
 */
@RestControllerAdvice
public class ResultExceptionHandler {
    /**
     * 通用异常处理方法
     *
     * @param businessException 业务异常类
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    public Result<?> handleException(BusinessException businessException) {
        businessException.printStackTrace();
        return Result.failed(businessException.getResultEnum());
    }
}
